<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <link rel="icon" type="image/x-icon" th:href="${application.iconPath}"/>
    <title>ssouser</title>
    <div th:include="../templates/common::html_header"></div>
</head>

<body>
<div class="layui-form contain ">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-inline">
                <input type="password" id="pwd" lay-verify="required" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" id="pwd1" lay-verify="pwd|compare" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" id="pwd2" lay-verify="comfirmPwd" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="save">保存</button>
                <button class="layui-btn layui-btn-primary" id="close">关闭</button>
            </div>
        </div>
    </form>
</div>

</body>
</html>

<div th:include="../templates/common::html_footer"></div>
<script>
    layui.use(['element', 'form', 'layer', 'verify', 'web', 'user'], function () {
        var element = layui.element;
        var form = layui.form;
        var layer = layui.layer;
        var web = layui.web;
        var user = layui.user;
        var contro_path = '/ssouser';

        form.verify({
            compare: function (value, item) {
                if ($("#pwd").val() == $("#pwd1").val()) {
                    return "新密码和原密码不能一样";
                }
            }
        });

        form.on('submit(save)', function (data) {
            var url = basePath + "/user/updatepwd";

            web.load();
            web.ajax(url, 'post',
                {pwd: $("#pwd").val(), newPwd: $("#pwd1").val()}
                , function (data) {
                    layer.alert("保存成功", {
                        icon: 1
                    }, function (index) {
                        user.cleanUser();
                        user.initData();
                        layer.close(index);//关闭当前层

                        var current_index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(current_index); //用父窗口的layer对象关闭当前弹出层

                        parent.location.reload();
                    });
                });
            return false;
        });
    });
</script>

